﻿
@{
    ViewBag.Title = "OutInKF";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
}


@{
    ViewBag.Title = "SPIndex";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}

<table id="Insiders_OutInKF_grid" class="easyui-datagrid" style="width:100%;" title="@ViewBag.NAME" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:false,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#Insiders_OutInKF_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="Insiders_OutInKF_tb" style="padding:2px 5px;">
    <input type="text" class="easyui-textbox" label="借阅人:" labelwidth="50px" labelalign="right" style="width:180px" id="Insiders_OutInKF_txtName" />
    <input type="text" class="easyui-textbox" label="档案:" labelwidth="50px" labelalign="right" style="width:180px" id="Insiders_OutInKF_txtDH" />
    <input type="text" class="easyui-textbox" label="题名:" labelwidth="50px" labelalign="right" style="width:180px" id="Insiders_OutInKF_txtTM" />
    <a href="javascript:void(0);" id="LogLogin_Index_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="Search()" style="width:110px;height:30px;">查询</a>
    @{
        if (@ViewBag.BrrStatus == "0")
        {
            <a href="javascript:void(0);" id="Insiders_SPIndex_btnQuery" class="easyui-linkbutton button-orange" iconCls="icon-redo" onclick="OutK()" style="width:110px;height:30px;">手动出库</a>
        }
        else
        {
            <a href="javascript:void(0);" id="Insiders_SPIndex_btnQuery" class="easyui-linkbutton button-orange" iconCls="icon-redo" onclick="InK()" style="width:110px;height:30px;">手动入库</a>
        }
    }
</div>
<script>
    $(document).ready(function () {
        $('#Insiders_OutInKF_grid').datagrid({
            url: '/Insiders/Get_ajaxOutInKFArchive?brrstatus=' +@ViewBag.BrrStatus+'&name=&dh=&tm=',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation();
    });
    

    function SearchPager(num, size) {

        $('#Insiders_OutInKF_grid').datagrid('options').url = '/Insiders/Get_ajaxOutInKFArchivePager?num=' + num +
            '&size=' + size;
        $('#Insiders_OutInKF_grid').datagrid('reload');
        $('#Insiders_OutInKF_grid').datagrid('options').pageNumber = num;
        $('#Insiders_OutInKF_grid').datagrid('options').pageSize = size;
    }


    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#Insiders_OutInKF_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                SearchPager(pageNumber, pageSize);
            }
        });
    }
    function Search()
    {
        var NAME = $('#Insiders_OutInKF_txtName').val();
        var DH = $('#Insiders_OutInKF_txtDH').val();
        var TM = $('#Insiders_OutInKF_txtTM').val();
        $('#Insiders_OutInKF_grid').datagrid('options').url = '/Insiders/Get_ajaxOutInKFArchive?brrstatus=' +@ViewBag.BrrStatus+'&name=' + NAME + '&dh=' + DH + '&tm=' + TM,
        $('#Insiders_OutInKF_grid').datagrid('load');
    }
    function OutK()
    {
        var rows = $('#Insiders_OutInKF_grid').datagrid('getChecked');
        var id = [];
        for (var i = 0; i < rows.length; i++) {
            id.push(rows[i].BI_ID);
        }
        $.messager.confirm('提示', '确定要手动出库吗?', function (r) {
            if (r) {
                $.ajax({
                    url: '/Insiders/ArchiveOutK',
                    type: 'post',
                    dataType: 'json',
                    data: { 'id': id },
                    success: function (data) {
                        //$.messager.alert('提示', '审批成功', 'info');
                        $('#Insiders_OutInKF_grid').datagrid('options').url = '/Insiders/Get_ajaxOutInKFArchive?brrstatus=' +@ViewBag.BrrStatus+'&name=&dh=&tm=',
                            $('#Insiders_OutInKF_grid').datagrid('load');
                    }
                });
            }
        });
    }
    function InK()
    {
        var rows = $('#Insiders_OutInKF_grid').datagrid('getChecked');
        var id = [];
        for (var i = 0; i < rows.length; i++) {
            id.push(rows[i].BI_ID);
        }
        $.messager.confirm('提示', '确定要手动入库吗?', function (r) {
            if (r) {
                $.ajax({
                    url: '/Insiders/ArchiveInK',
                    type: 'post',
                    dataType: 'json',
                    data: { 'id': id },
                    success: function (data) {
                        //$.messager.alert('提示', '审批成功', 'info');
                        $('#Insiders_OutInKF_grid').datagrid('options').url = '/Insiders/Get_ajaxOutInKFArchive?brrstatus=' +@ViewBag.BrrStatus+'&name=&dh=&tm=',
                            $('#Insiders_OutInKF_grid').datagrid('load');
                    }
                });
            }
        });
    }
    function formatStatus(value, row) {
        if (value == 0) {
            return "等待出库";
        }
        else if (value == 1) {
            return "借出";
        }
        else {
            return "已归还";
        }
    }
    function formatSPValue(value, row) {
        if (value == 0) {
            return "未审批";
        }
        else if (value == 1) {
            return "通过";
        }
        else {
            return "拒绝";
        }
    }
    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            var month = (time.getMonth() + 1);
            if (month < 9)
                month = "0" + month;
            var day = time.getDate();
            if (day < 9)
                day = "0" + day;

            var hm = '';
            var hours = time.getHours(); var mint = time.getMinutes();
            if (hours == 0 && mint == 0)
                hm = '';
            else {
                if (hours < 9)
                    hours = "0" + hours;
                if (mint < 9)
                    mint = "0" + mint;

                hm = hours + ":" + mint;
            }


            return time.getFullYear() + "-" + month + "-" + day + " " + hm; ///+ ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
    function formatEnd(value, row) {
        return '<a href="javascript:void(0);" id="Insiders_SPIndex_btnQuery" onclick="EndCK(' + value + ')"><span style="color:red">取消借阅</span></a>';
    }

    function EndCK(id) {
        $.messager.confirm('提示', '确定要取消出库吗?', function (r) {
            if (r) {
                $.ajax({
                    url: '/Insiders/EndCK',
                    type: 'post',
                    dataType: 'json',
                    data: { 'id': id },
                    success: function (data) {
                        if (data == "-1")
                            $.messager.alert('提示', '取消发生错误!', 'error');
                        else if (data == "0")
                            $.messager.alert('提示', '数据已经发生变化，请重新刷新页面再进行操作!', 'info');
                        else {
                            UpdateList();
                        }
                    }
                });
            }
        });
    }

    ///刷新之后，把存放数据清除
    function UpdateList() {
        ///closeWin();
        QueryPager($('#Insiders_OutInKF_grid').datagrid('options').pageNumber, $('#Insiders_OutInKF_grid').datagrid('options').pageSize);
    }

    function InitPagenation() {
        //设置分页控件
        var p = $('#Insiders_OutInKF_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#Insiders_OutInKF_grid').datagrid('options').url = '/Insiders/Get_ajaxOutInKFArchivePager?num=' + num + '&size=' + size;
        $('#Insiders_OutInKF_grid').datagrid('reload');
        $('#Insiders_OutInKF_grid').datagrid('options').pageNumber = num;
        $('#Insiders_OutInKF_grid').datagrid('options').pageSize = size;
        return;
    }
</script>




